import {
  getjiaoyiequshi,
  getpinleijiaoyie,
  getjiaoyifengzhi,
  getdanpinjiaoyie,
  getkeliuqushi,
  getkequnhuaxiang,
  getjiancepinleifenbu,
  getbuhegechanpin,
  getbuhegetanwei,
  getbuhegeshijian,
  getjiancequshi,
  getkeliuloudou,
  getkequnhuaxiangsex,
  getkeliufengzhi,
  getweekkeliufengzhi,
  getjiaoyibaobiao,
  getkeliubaobiao,
  getjiancebaobiao,
  getRegionalChartsData,
  getFrequentActivities,
  getFrequentActivities2
} from "@/api/businessReport";
// import { getRegionalChartsData } from "@/api/peopleNumber";

import * as types from "../../mutation-types";
export default {
  namespaced: true, // 封闭
  state: {
    jiaoyiequshioptions: {},
    jiaoyiliangqushioptions: {},
    pinleijiaoyiefenxioptions: {},
    pinleijiaoyiliangfenxioptions: {},
    pinleikeydanjiaoptions: {},
    jiaoyifengzhifenxioptions: {},
    keliuqushioptions: {},
    kequnhuaxiangoptions: {},
    danpinjiaoyiliangoptions: {},
    danpinjiaoyieoptions: {},
    rukourelifenxioptions: {},
    jiancepinleifenbuoptions: {},
    buhegechanpinoptions: {},
    buhegetanweioptions: {},
    buhegeshijianoptions: {},
    jiancequshioptions: {},
    keliuloudouoptions: {},
    keliufengzhifenxioptions: {},
    weekkeliufengzhifenxioptions: {},
    lastTimeOptions: {},
    lastTimeOptions2: {},
  },
  mutations: {
    // 交易额趋势
    [types.JIAO_YI_E_QU_SHI](state, options) {
      state.jiaoyiequshioptions = options;
    },
    [types.JIAO_YI_LIANG_QU_SHI](state, options) {
      state.jiaoyiliangqushioptions = options;
    },

    [types.PIN_LEI_JIAO_YI_E](state, options) {
      state.pinleijiaoyiefenxioptions = options;
    },
    [types.PIN_LEI_JIAO_YI_LIANG](state, options) {
      state.pinleijiaoyiliangfenxioptions = options;
    },
    [types.PIN_LEI_KE_DAN_JIA](state, options) {
      state.pinleikeydanjiaoptions = options;
    },

    [types.JIAO_YI_FENG_ZHI_FEN_XI](state, options) {
      state.jiaoyifengzhifenxioptions = options;
    },
    [types.DAN_PIN_JIAO_YI_E](state, options) {
      state.danpinjiaoyieoptions = options;
    },
    [types.DAN_PIN_JIAO_YI_LIANG](state, options) {
      state.danpinjiaoyiliangoptions = options;
    },

    [types.KE_LIU_QU_SHI](state, options) {
      state.keliuqushioptions = options;
    },

    [types.KE_QUN_HUA_XIANG](state, options) {
      state.kequnhuaxiangoptions = options;
    },

    [types.RU_KOU_RE_LI_FEN_XI](state, options) {
      state.rukourelifenxioptions = options;
    },

    [types.JIAN_CE_PIN_LEI_FEN_BU](state, options) {
      state.jiancepinleifenbuoptions = options;
    },

    [types.BU_HE_GE_CHAN_PIN](state, options) {
      state.buhegechanpinoptions = options;
    },

    [types.BU_HE_GE_TAN_WEI](state, options) {
      state.buhegetanweioptions = options;
    },

    [types.BU_HE_GE_SHI_JIAN](state, options) {
      state.buhegeshijianoptions = options;
    },

    [types.JIAN_CE_QU_SHI](state, options) {
      state.jiancequshioptions = options;
    },

    [types.KE_LIU_LOU_DOU_YUE_DU](state, options) {
      state.keliuloudouoptions = options;
    },

    [types.KE_LIU_FENG_ZHI_FEN_XI](state, options) {
      state.keliufengzhifenxioptions = options;
    },

    [types.WEEK_KE_LIU_FENG_ZHI_FEN_XI](state, options) {
      state.weekkeliufengzhifenxioptions = options;
    },

    [types.SET_LAST_TIME_DATA_1](state, options) {
      state.lastTimeOptions = options
    },
    [types.SET_LAST_TIME_DATA_2](state, options) {
      state.lastTimeOptions2 = options
    },
  },
  getters: {},
  actions: {
    // 交易报表 数据看板 sort 1 月 2 日 3 周 4 季度 5年
    async fetchjiaoyibaobiao(context, payload) {
      console.log('payload')
      console.log(payload)
      const {
        year,
        month,
        day,
        week,
        quarter,
        yesterdayYear,
        yesterdayMonth,
        yesterdayDay,
        yesterdayWeek,
        yesterdayQuarter,
        marketId,
        sort
      } = payload;

      let data = {};
      let yesterdayData = {};
      try {
        const f1 = await getjiaoyibaobiao(
          year,
          month,
          day,
          week,
          quarter,
          marketId,
          sort
        ); // 本月
        const f2 = await getjiaoyibaobiao(
          yesterdayYear,
          yesterdayMonth,
          yesterdayDay,
          yesterdayWeek,
          yesterdayQuarter,
          marketId,
          sort
        ); // 上月
        await Promise.all([f1, f2])
          .then(result => {
            yesterdayData = result[1].data;
            data = result[0].data;
          })
          .catch(error => {
            console.log(error);
          });
      } catch (err) {
        // console.log('modules-home-index.js-fetchMarketDailySales', err)
      }
      return [data, yesterdayData];
    },



    // 交易额/量趋势
    async fetchjiaoyiequshi(context, payload) {
      const { year, month, day, week, quarter, id, sort } = payload;
      try {
        const { data } = await getjiaoyiequshi(
          year, month, day, week, quarter, id, sort
        );
        const options = {
          color: ["#3c90f7"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                if (sort === 4) {
                  return data.map(item => {
                    let time = `${item.Key.slice(6,7)}月`;
                    return time;
                  });
                } else if (sort === 1 || sort === 2 || sort === 3) {
                  return data.map(item => {
                    let time = item.Key.split(" ")[0];
                    return time;
                  });
                } else if (sort === 5) {
                  return data.map(item => {
                    let time = item.Key.slice(0,7)
                    return time;
                  });
                }
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              data: (() => {
                return data.map(item => item.Sales / 100);
              })()
            }
          ]
        };
        const options2 = {
          color: ["#3c90f7"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                if (sort === 4) {
                  return data.map(item => {
                    let time = `${item.Key.slice(6, 7)}月`;
                    return time;
                  });
                } else if (sort === 1 || sort === 2 || sort === 3) {
                  return data.map(item => {
                    let time = item.Key.split(" ")[0];
                    return time;
                  });
                } else if (sort === 5) {
                  return data.map(item => {
                    let time = item.Key.slice(0, 7)
                    return time;
                  });
                }
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              data: (() => {
                return data.map(item => item.Weight / 1000);
              })()
            }
          ]
        };
        context.commit(types.JIAO_YI_E_QU_SHI, options);
        context.commit(types.JIAO_YI_LIANG_QU_SHI, options2);
      } catch (err) {
        console.log(err);
      }
    },

    // 客流趋势
    async fetchkeliuqushi(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getkeliuqushi(date, type);
        const options = {
          noDataLoadingOption: {
            text: "暂无数据",
            effect: "bubble",
            effectOption: {
              effect: {
                n: 0
              }
            }
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "cross",
              crossStyle: {
                backgroundColor: "#283b56"
              }
            }
          },
          color: ['#f65f2f', '#5ab1ef', '#f4516c'],
          legend: {
            data: ["当前月当天客流峰值", "上一个月当天客流峰值"]
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                if (type === 'quarter') {
                  return data.map(item => {
                    let time = `${item.key.slice(1, 2)}月`;
                    return time;
                  });
                } else if (type === 'day' || type === 'week' || type === 'month') {
                  return data.map(item => {
                    let time = `${date.slice(5, 6)}月${item.key}日`;
                    return time;
                  });
                } else if (type === 'year') {
                  return data.map(item => {
                    let time = `${date.slice(0,4)}年${item.key}月`
                    return time;
                  });
                }
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            },
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              name: "当前月当天客流峰值",
              data: (() => {
                return data.map(item => item.nowCount);
              })()
            },
            {
              type: "bar",
              name: "上一个月当天客流峰值",
              yAxisIndex: 1,
              data: (() => {
                return data.map(item => item.previousCount);
              })()
            }
          ]
        };
        context.commit(types.KE_LIU_QU_SHI, options);
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 品类交易额/量/客单价
    async fetchpinleijiaoyie(context, payload) {
      const { year, month, day, week, quarter, id, sort } = payload;
      try {
        const { data } = await getpinleijiaoyie(year, month, day, week, quarter, id, sort)
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: (data[0].Sales / 100).toFixed() },
                { value: (data[1].Sales / 100).toFixed() },
                { value: (data[2].Sales / 100).toFixed() },
                { value: (data[3].Sales / 100).toFixed() },
                { value: (data[4].Sales / 100).toFixed() },
                { value: (data[5].Sales / 100).toFixed() }
              ]
            }
          ]
        };
        const options2 = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              radius: ["50%", "70%"],
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: (data[0].Weight / 1000).toFixed() },
                { value: (data[1].Weight / 1000).toFixed() },
                { value: (data[2].Weight / 1000).toFixed() },
                { value: (data[3].Weight / 1000).toFixed() },
                { value: (data[4].Weight / 1000).toFixed() },
                { value: (data[5].Weight / 1000).toFixed() }
              ]
            }
          ]
        };
        const options3 = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                return data.map(item => {
                  let time = item.Key.split(" ")[0];
                  return time;
                });
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              data: (() => {
                return data.map(item => item.PCT.toFixed(2));
              })()
            }
          ]
        };
        context.commit(types.PIN_LEI_JIAO_YI_E, options);
        context.commit(types.PIN_LEI_JIAO_YI_LIANG, options2);
        context.commit(types.PIN_LEI_KE_DAN_JIA, options3);

        let chartArr={chartArr1:[],chartArr2:[]}
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff',"#ff66ff"]
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.chartArr1.push(
            {
              value: (newChartList[i].Sales/100).toFixed(),
              key: newChartList[i].Key,
              color: newChartList[i].color
            }
          ),
          chartArr.chartArr2.push(
            {
              value: (newChartList[i].Weight/1000).toFixed(),
              key: newChartList[i].Key,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },
    // 交易峰值分析
    async fetchjiaoyifengzhi(context, payload) {
      const { year, month, day, week, quarter, id, sort } = payload;
      try {
        const { data } = await getjiaoyifengzhi(year, month, day, week, quarter, id, sort);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: data[0].Sales / 100 },
                { value: data[1].Sales / 100 },
                { value: data[2].Sales / 100 },
                { value: data[3].Sales / 100 }
              ]
            }
          ]
        };
        context.commit(types.JIAO_YI_FENG_ZHI_FEN_XI, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff']
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: (newChartList[i].PCT/100).toFixed(2),
              key: newChartList[i].Key,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 单品交易额/量分析 sort 1金额 2重量
    async fetchdanpinjiaoyie(context, payload) {
      const { year, month, day, week, quarter, id, sort } = payload;
      try {
        const { data } = await getdanpinjiaoyie(year, month, day, week, quarter, id, sort);
        const options = {
          color: ["#3c90f7"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                return data.map(item => {
                  let time = item.Key.split(" ")[0];
                  return time;
                });
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              data: (() => {
                return data.map(item => item.Sales / 100);
              })()
            }
          ]
        };
        const options2 = {
          color: ["#3c90f7"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                return data.map(item => {
                  let time = item.Key.split(" ")[0];
                  return time;
                });
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              data: (() => {
                return data.map(item => item.Weight / 1000);
              })()
            }
          ]
        };
        context.commit(types.DAN_PIN_JIAO_YI_E, options);
        context.commit(types.DAN_PIN_JIAO_YI_LIANG, options2);
        return data;
      } catch (err) {
        console.log(err);
      }
    },


    // 客流报表 数据看板
    async fetchkeliubaobiao(context, payload) {
      const { year, month, yesterdayYear, yesterdayMonth, date, type } = payload;
      let data = {};
      let yesterdayData = {};
      try {
        const f1 = await getkeliubaobiao(year, month, date, type); // 本月
        const f2 = await getkeliubaobiao(yesterdayYear, yesterdayMonth, date, type); // 上月
        await Promise.all([f1, f2])
          .then(result => {
            yesterdayData = result[1].data;
            data = result[0].data;
          })
          .catch(error => {
            console.log(error);
          });
      } catch (err) {
        // console.log('modules-home-index.js-fetchMarketDailySales', err)
      }
      return [data, yesterdayData];
    },



    // 客流漏斗(月度)
    async fetchkeliuloudou(context, payload) {
      const { year, month, date, type } = payload;
      try {
        const { data } = await getkeliuloudou(year, month, date, type);
        var xAxis = [];
        var mainSeries = [];

        var max = 1;
        var min = 0;
        for (var i = 0; i < data.length; i++) {
          xAxis[i] = data[i].name + " " + data[i].cnt;
          mainSeries[i] = {
            value: data[i].cnt,
            name: data[i].name + " " + data[i].cnt
          };

          if (max < data[i].cnt) {
            max = data[i].cnt;
          }

          if (min > data[i].cnt) {
            min = data[i].cnt;
          }
        }
        const options = {
          color: ['#427eb4', '#61ae7b', '#e79f3c', '#b24434'],
          tooltip: {
            trigger: "item",
            formatter: "{a} <br/>{b} : {c}%"
          },
          legend: {
            orient: "vertical",
            left: "left",
            top: "center",
            show: false,
            data: xAxis
          },

          series: [
            {
              name: "漏斗图",
              type: "funnel",
              left: "10%",
              top: 60,
              // x2: 80,
              bottom: 60,
              width: "80%",
              // height: {totalHeight} - y - y2,
              min: min,
              max: max,
              minSize: "20%",
              maxSize: "100%",
              sort: "descending",
              gap: 12,
              label: {
                show: true,
                position: "inside"
              },
              labelLine: {
                length: 10,
                lineStyle: {
                  width: 1,
                  type: "solid"
                }
              },
              itemStyle: {
                borderColor: "#fff",
                borderWidth: 1
              },
              emphasis: {
                label: {
                  fontSize: 20
                }
              },
              data: mainSeries
            }
          ]
        };
        context.commit(types.KE_LIU_LOU_DOU_YUE_DU, options);
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 客群画像(图)
    async fetchkequnhuaxiang(context, payload) {
      const { year, month, date, type } = payload;
      try {
        const { data } = await getkequnhuaxiang(year, month, date, type);
        const options = {
          color: ["#3c90f7"],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              // 坐标轴指示器，坐标轴触发有效
              type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: [
                "小于20岁",
                "20-29岁",
                "30-39岁",
                "40-49岁",
                "50-59岁",
                "60岁以上"
              ],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              name: "直接访问",
              type: "bar",
              barWidth: "60%",
              data: [
                data.lass_20_total_number,
                data.lass_30_total_number,
                data.lass_40_total_number,
                data.lass_50_total_number,
                data.lass_60_total_number,
                data.greater_equal_70_total_number
              ]
            }
          ]
        };
        context.commit(types.KE_QUN_HUA_XIANG, options);
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 客群画像(人数)
    async fetchkequnhuaxiangsex(context, payload) {
      const { startDate, endDate, date, type } = payload;
      try {
        const { data } = await getkequnhuaxiangsex(
          startDate,
          endDate,
          date, type
        );
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 客流峰值分析(饼图)
    async fetchkeliufengzhi(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getkeliufengzhi(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: data.forenoonNumber },
                { value: data.nooningNumber },
                { value: data.afternoonNumber },
                { value: data.nightNumber }
              ]
            }
          ]
        };
        context.commit(types.KE_LIU_FENG_ZHI_FEN_XI, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff']
        let time=["上午","中午","下午","晚上"]
        let value=[data.forenoonNumber,data.nooningNumber,data.afternoonNumber,data.nightNumber]
        const newColorArr = colorArr.map(item => ({ color: item }))
        const newtimeArr = time.map(item => ({ time: item }))
        const newvalueArr = value.map(item => ({ data: item }))
        let newChartList = newtimeArr.map((item, index) => {
          return { ...item, ...newColorArr[index],...newvalueArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].data,
              key: newChartList[i].time,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 客流峰值分析(柱状图)
    async fetchweekkeliufengzhi(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getweekkeliufengzhi(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: [
            {
              type: "category",
              data: [
                "周一峰值",
                "周二峰值",
                "周三峰值",
                "周四峰值",
                "周五峰值",
                "周六峰值",
                "周日峰值"
              ],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            }
          ],
          series: [
            {
              name: "直接访问",
              type: "bar",
              barWidth: "60%",
              data: [
                data.monday,
                data.tuesday,
                data.wednesday,
                data.thursday,
                data.friday,
                data.saturday,
                data.sunday
              ]
            }
          ]
        };
        context.commit(types.WEEK_KE_LIU_FENG_ZHI_FEN_XI, options);
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 入口热力分析
    async fetchrukourelifenxi(context, payload) {
      const { startDate, endDate, date, type } = payload;
      try {
        const { data } = await getRegionalChartsData(startDate, endDate, date, type);
        console.log("入口热力",data)
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: (() => {
                let arr = []
                for (let i = 1; i < data.chart.list.length; i++) {
                  arr.push({ value: data.chart.list[i].removelDuplicateCnt })
                }
                return arr
              })()
            }
          ]
        };
        context.commit(types.RU_KOU_RE_LI_FEN_XI, options);
        let chartArr = []

        let colorArr = ['', '#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff',"#ff66ff"]
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.chart.list.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 1; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].removelDuplicateCnt,
              key: newChartList[i].region,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 回访活跃度分析(饼图1)
    async fetchFrequentActivities(context, payload) {
      const { targetDate, date, type } = payload;
      try {
        const { data } = await getFrequentActivities(targetDate, date, type)
        let options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: data[0].cnt },
                { value: data[1].cnt },
                { value: data[2].cnt },
                { value: data[3].cnt }
              ]
            }
          ]
        }
        context.commit(types.SET_LAST_TIME_DATA_1, options)
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff']
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].cnt,
              key: newChartList[i].name,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err)
      }
    },

    // 回访活跃度分析(饼图2)
    async fetchFrequentActivities2(context, payload) {
      const { targetDate, date, type } = payload;
      try {
        const { data } = await getFrequentActivities2(targetDate, date, type)
        let options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: [
                { value: data[0].cnt },
                { value: data[1].cnt },
                { value: data[2].cnt },
                { value: data[3].cnt }
              ]
            }
          ]
        }
        context.commit(types.SET_LAST_TIME_DATA_2, options)
        let chartArr={chartArr1:[],chartArr2:[]}
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff']
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        chartArr.chartArr1.push(
          {
            value: newChartList[0].cnt,
            key: newChartList[0].name,
            color: newChartList[0].color
          }
        )
        for (let i = 1; i < newChartList.length; i++) {
          chartArr.chartArr2.push(
            {
              value: newChartList[i].cnt,
              key: newChartList[i].name,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err)
      }
    },


    // 检测报表 数据看板
    async fetchjiancebaobiao(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getjiancebaobiao(date, type);
        return data;
      } catch (err) { }
    },

    // 检测趋势
    async fetchjiancequshi(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getjiancequshi(date, type);
        const options = {
          noDataLoadingOption: {
            text: "暂无数据",
            effect: "bubble",
            effectOption: {
              effect: {
                n: 0
              }
            }
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "cross",
              crossStyle: {
                backgroundColor: "#283b56"
              }
            }
          },
          color: ['#f65f2f', '#5ab1ef', '#3c90f7'],
          legend: {
            data: ["检测摊位数", "检测品种数", "检测不合格数"]
          },
          xAxis: [
            {
              type: "category",
              data: (() => {
                if (type === 'quarter'){
                  return data.map(item => {
                    let time = `${item.key.slice(1, 2)}月`;
                    return time;
                  });
                } else if (type === 'day' || type === 'week' || type === 'month'){
                  return data.map(item => {
                    let time = `${date.slice(5, 6)}月${item.key}日`;
                    return time;
                  });
                } else if (type === 'year') {
                  return data.map(item => {
                    let time = `${date.slice(0, 4)}年${item.key}月`;
                    return time;
                  });
                }
              })(),
              axisPointer: {
                type: "shadow"
              }
            }
          ],
          yAxis: [
            {
              type: "value"
            },
            {
              type: "value"
            }
          ],
          series: [
            {
              type: "bar",
              name: "检测摊位数",
              data: (() => {
                return data.map(item => item.businessCount);
              })()
            },
            {
              type: "bar",
              name: "检测品种数",
              yAxisIndex: 1,
              data: (() => {
                return data.map(item => item.goodCount);
              })()
            },
            {
              type: "line",
              name: "检测不合格数",
              yAxisIndex: 1,
              data: (() => {
                return data.map(item => item.noqualifiedCount);
              })()
            }
          ]
        };
        context.commit(types.JIAN_CE_QU_SHI, options);
        return data;
      } catch (err) {
        console.log(err);
      }
    },

    // 检测品类分布
    async fetchjiancepinleifenbu(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getjiancepinleifenbu(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: (() => {
                let arr = []
                for (let i = 0; i < data.length; i++) {
                  arr.push({ value: data[i].count })
                }
                return arr
              })()
            }
          ]
        };
        context.commit(types.JIAN_CE_PIN_LEI_FEN_BU, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff']
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].count,
              key: newChartList[i].businessTypeName,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 不合格产品分析
    async fetchbuhegechanpin(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getbuhegechanpin(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: (() => {
                let arr = []
                for (let i = 0; i < data.length; i++) {
                  arr.push({ value: data[i].count })
                }
                return arr
              })()
            }
          ]
        };
        context.commit(types.BU_HE_GE_CHAN_PIN, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff',"#ff66ff"]
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].count,
              key: newChartList[i].sampleName,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 不合格摊位
    async fetchbuhegetanwei(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getbuhegetanwei(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              radius: ["50%", "70%"],
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: (() => {
                let arr = []
                for (let i = 0; i < data.length; i++) {
                  arr.push({ value: data[i].count })
                }
                return arr
              })()
            }
          ]
        };
        context.commit(types.BU_HE_GE_TAN_WEI, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff',"#ff66ff"]
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].count,
              key: newChartList[i].businessName,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    },

    // 不合格时间
    async fetchbuhegeshijian(context, payload) {
      const { date, type } = payload;
      try {
        const { data } = await getbuhegeshijian(date, type);
        const options = {
          color: ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9'],
          series: [
            {
              type: "pie",
              hoverAnimation: false,
              label: {
                normal: {
                  show: false,
                  position: "center"
                }
              },
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              data: (() => {
                let arr = []
                for (let i = 0; i < data.length; i++) {
                  arr.push({ value: data[i].count })
                }
                return arr
              })()
            }
          ]
        };
        context.commit(types.BU_HE_GE_SHI_JIAN, options);
        let chartArr=[]
        let colorArr = ['#3c90f7', '#55bfc0', '#5ebe67', '#f4cd49', '#e05666', '#7c4bd9', '#e79f3c', '#ef8a8b','#cc00ff',"#ff66ff"]
        const newColorArr = colorArr.map(item => ({ color: item }))
        let newChartList = data.map((item, index) => {
          return { ...item, ...newColorArr[index] }
        })
        for (let i = 0; i < newChartList.length; i++) {
          chartArr.push(
            {
              value: newChartList[i].count,
              key: newChartList[i].time,
              color: newChartList[i].color
            }
          )
        }
        return chartArr;
      } catch (err) {
        console.log(err);
      }
    }
  }
};
